package sparrowGui.skin
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	import sparrowGui.ComponentDraw;
	import sparrowGui.SparrowGUI;
	import sparrowGui.utils.PubFun;
	import sparrowGui.vars.ComboBoxVars;
	import sparrowGui.vars.ComponentVars;
	
	/**
	 * 组合框皮肤,皮肤里面有一个框和一个按钮
	 * @author Pelephone
	 */	
	public class ComboBoxSkin extends TagsBtnSkin
	{
		private var _width:int		= 60;
		private var _height:int	= 18;
		private var _btnWH:int		= 14;
		private var _padding:int	= 2;
		public function ComboBoxSkin()
		{
			super();
		}
		
		override protected function init():void
		{
			drawRect(_width,_height);
			var txt:TextField = new TextField();
			txt.autoSize = TextFieldAutoSize.LEFT;
			addChild(txt);
			
			var arrSp:Shape = PubFun.drawArrow(0);
			var normalVar:ComponentVars	= SparrowGUI.getIns().componentVar;
			normalVar.setBorder(1);
			normalVar.setWH(_btnWH,_btnWH);
			normalVar.setBorderColor(0xcccccc);
			upState = new ComponentDraw(normalVar);
			upState.name = "upState";
			arrSp.x = arrSp.y = 2;
			upState.addChild(arrSp);
			
			var selectVar:ComponentVars	= SparrowGUI.getIns().componentVar;
			selectVar.bgColor = 0x777777;
			selectVar.setBorder(1);
			selectVar.setBorderColor(0xCCCCCC);
			selectVar.setWH(_btnWH,_btnWH);
			selectState = new ComponentDraw(selectVar);
			selectState.name = "selectState";
			arrSp = PubFun.drawArrow(0);
			arrSp.x = arrSp.y = 2;
			selectState.addChild(arrSp);
			
			var overVar:ComponentVars	= SparrowGUI.getIns().componentVar;
			overVar.bgColor = 0xAAAAAA;
			overVar.setBorder(1);
			overVar.setBorderColor(0xcccccc);
			overVar.setWH(_btnWH,_btnWH);
			overState = new ComponentDraw(overVar);
			overState.name = "overState";
			arrSp = PubFun.drawArrow(0);
			arrSp.x = arrSp.y = 2;
			overState.addChild(arrSp);
			
			downState = new ComponentDraw(overVar);
			downState.name = "downState";
			arrSp = PubFun.drawArrow(0);
			arrSp.x = arrSp.y = 2;
			downState.addChild(arrSp);
			
			hitTestState = null;
			
			upState.x = selectState.x = downState.x = overState.x = (_width - _btnWH - _padding);
			upState.y = selectState.y = downState.y = overState.y = _padding;
		}
		
		override public function set width(val:Number):void
		{
			_width = val;
			drawRect(val,_height);
			
			upState.x = selectState.x = downState.x = overState.x = _width - _btnWH - _padding;
		}
		
		override public function set height(val:Number):void
		{
			return;
		}
		
		private function drawRect(w:int,h:int):void
		{
			graphics.clear();
			graphics.beginFill(0xFFFFFF);
			graphics.drawRect(0,0,w,h);
			graphics.endFill();
		}
	}
}